package com.example.king.openglenvdemo.nativegl;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLSurfaceView;
import android.os.Environment;
import android.util.Log;
import com.example.king.openglenvdemo.R;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

/**
 * Created by shiyanjin on 18-11-14.
 */
public class GL2JNIView extends GLSurfaceView {


    public GL2JNIView(Context context) {
        super(context);

        setEGLConfigChooser(8, 8, 8, 0, 16, 0);
        setEGLContextClientVersion(3);
        setRenderer(new Renderer(context));

        setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    }



    private class Renderer implements GLSurfaceView.Renderer {
        Bitmap bitmap;

        private Context mContext;

        public Renderer(Context context) {
            mContext = context;
        }

        @Override
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = false;

            bitmap = BitmapFactory.decodeResource(
                    mContext.getResources(), R.drawable.huai_jiu, options);
        }

        @Override
        public void onSurfaceChanged(GL10 gl, int width, int height) {
            GLES2JNILib.init(width, height);
        }

        @Override
        public void onDrawFrame(GL10 gl) {
            String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test_h264.yuv";
            Log.d("kkunion","yuv path :" +path);

            GLES2JNILib.step(path);
        }
    }
}
